﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ucFavorite : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
      string currentPath = Request.AppRelativeCurrentExecutionFilePath;
      if (Profile.FavoriteURLs.Contains(currentPath))
      {
        ib_favorite.ImageUrl = "~/Images/SavedStar.png";
      }
      else
      { 
        ib_favorite.ImageUrl = "~/Images/FilledStar.png";
      }
    }

    protected void ib_favorite_Click(object sender, ImageClickEventArgs e)
    {
      try
      {
        string currentPath = Request.AppRelativeCurrentExecutionFilePath;
        if (Profile.FavoriteURLs.Contains(currentPath))
        {
          Profile.FavoriteURLs.Remove(currentPath);
          ((ImageButton)sender).ImageUrl = "~/Images/FilledStar.png";
        }
        else
        {
          Profile.FavoriteURLs.Add(currentPath);
          ((ImageButton)sender).ImageUrl = "~/Images/SavedStar.png";
        }

        GridView gv = Page.Master.FindControl("gv_favorite") as GridView;
        if (gv != null)
        {
          gv.DataSource = Profile.FavoriteURLs;
          gv.DataBind();
        }
      }
      catch (Exception ex)
      {
        throw ex;
      }
      
    }
}